package com.example.learn.hwod;

import java.util.Scanner;
import java.util.StringJoiner;

public class _04TLV解码 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String target = sc.nextLine();

        String[] split = sc.nextLine().split(" ");
        System.out.println(solution(target,split));


    }

    private static String solution(String target, String[] split) {

        StringJoiner result = new StringJoiner(" ");

        for (int i = 0; i < split.length; ) {
            String tag = split[i++];
            String t1 = split[i++];
            String t2 = split[i++];
            int len = Integer.parseInt(t2+t1,16);
            if (tag.equals(target)) {

                for (int j = 0; j < len; j++) {
                    result.add(split[i++]);
                }
                return result.toString();


            }else{
                i=i+len;
            }
        }
        return null;
    }
}
